/* function TreeNode(x) {
    this.val = x;
    this.left = null;
    this.right = null;
} */
function IsBalanced_Solution(pRoot)
{
    // write code here
    if(pRoot === null) return true
    let left = treeDeepth(pRoot.left)
    let right = treeDeepth(pRoot.right)
    return Math.abs(right - left) <= 1 && IsBalanced_Solution(pRoot.left) && IsBalanced_Solution(pRoot.right)
}
function treeDeepth(root){
  if(root === null) return 0
  let left = treeDeepth(root.left)
  let right = treeDeepth(root.right)
  return left > right ? left + 1 : right + 1
}
module.exports = {
    IsBalanced_Solution : IsBalanced_Solution
};